﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace SeachAndShareDemo.Views
{
    public sealed partial class SearchResults : Page
    {
        public SearchResults()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs arg)
        {
            PageTitle.Text = string.Format(PageTitle.Text, arg.Parameter.ToString());
            MySearchBox.SuggestionsRequested += ViewModel.SuggestionsRequested;
            MySearchBox.QuerySubmitted += (s, e) => this.Frame.Navigate(typeof(SearchResults), e.QueryText);
            MySearchBox.ResultSuggestionChosen += (s, e) => new MessageDialog("Load " + e.Tag).ShowAsync();
            this.ViewModel.Search(arg.Parameter.ToString());
            base.OnNavigatedTo(arg);
        }

        ViewModels.SearchResultsViewModel ViewModel { get { return this.DataContext as ViewModels.SearchResultsViewModel; } }

        private void Button_Click(object sender, RoutedEventArgs e) { this.Frame.GoBack(); }

        private void GridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            new MessageDialog("Load " + (e.ClickedItem as SeachAndShareDemo.Models.ColorItem).Name).ShowAsync();
        }
    }
}
